<template>
  <!-- 顶部头部栏 -->
  <div class="topheader">
    <div class="container">
      <div class="row align-items-center">
        <div class="col-md-4">
          <div class="d-flex align-items-center">
            <div class="currency-picker me-3">
              <span class="selected-currency">CNY</span>
            </div>
            <div class="language-dropdown me-3">
              <span class="language-dd">中文</span>
            </div>
            <p class="phone-no mb-0">
              <a href="tel:400-000-0000" class="text-decoration-none">
                <i class="fas fa-phone"></i>
                <span>400-000-0000</span>
              </a>
            </p>
          </div>
        </div>

        <div class="col-md-4 text-center d-none d-md-block">
          <p class="default-msg mb-0">
            <i class="fas fa-truck me-2"></i>
            满99元免费配送
          </p>
        </div>

        <div class="col-md-4">
          <div class="myaccount-links text-end">
            <ul class="customer-links list-inline mb-0">
              <li class="list-inline-item">
                <router-link to="/checkout" class="text-decoration-none">
                  <i class="fas fa-credit-card me-1"></i>结账
                </router-link>
              </li>
              <li class="list-inline-item">
                <router-link
                  to="/profile"
                  class="text-decoration-none"
                  v-if="userStore.isLoggedIn"
                >
                  <i class="fas fa-user-circle me-1"></i>
                  {{ userStore.userInfo?.name || userStore.userInfo?.username || '我的账户' }}
                </router-link>
                <router-link to="/login" class="text-decoration-none" v-else>
                  <i class="fas fa-sign-in-alt me-1"></i>我的账户
                </router-link>
              </li>
              <li class="list-inline-item" v-if="!userStore.isLoggedIn">
                <router-link to="/login" class="text-decoration-none">
                  <i class="fas fa-sign-in-alt me-1"></i>登录
                </router-link>
                <span class="mx-1">/</span>
                <router-link to="/register" class="text-decoration-none">
                  <i class="fas fa-user-plus me-1"></i>注册
                </router-link>
              </li>
              <li class="list-inline-item" v-else>
                <a href="javascript:void(0)" @click="handleLogout" class="text-decoration-none">
                  <i class="fas fa-sign-out-alt me-1"></i>退出
                </a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>

  <!-- 主头部 -->
  <header class="header header-1">
    <div class="container">
      <div class="row align-items-center py-3">
        <!-- 移动端菜单图标 -->
        <div class="col-3 d-block d-lg-none mobile-icons">
          <button
            type="button"
            class="btn btn-link p-0 mobile-nav-toggle"
            @click="toggleMobileMenu"
          >
            <i class="fas fa-bars" v-if="!showMobileMenu"></i>
            <i class="fas fa-times" v-else></i>
          </button>
        </div>

        <!-- Logo -->
        <div class="col-6 col-lg-3 logo">
          <router-link to="/" class="text-decoration-none">
            <div class="d-flex align-items-center">
              <i class="fas fa-shopping-bag fa-2x text-primary me-2 d-none d-xl-block"></i>
              <div>
                <h2 class="mb-0 text-primary fw-bold">SHOPLOOK</h2>
                <small class="text-muted d-none d-xl-block">品质生活，从这里开始</small>
              </div>
            </div>
          </router-link>
        </div>

        <!-- 搜索框 -->
        <div class="col-lg-5 d-none d-lg-block">
          <div class="header-search position-relative">
            <form class="form d-flex" @submit.prevent="handleSearch">
              <div class="search-wrapper w-100 position-relative">
                <div class="searchField">
                  <input
                    type="text"
                    v-model="searchKeyword"
                    placeholder="搜索商品..."
                    class="form-control border-0"
                    @input="onSearchInput"
                    @focus="showSearchSuggestions = true"
                    @blur="hideSearchSuggestions"
                  />
                  <button type="submit" class="action btn btn-primary">
                    <i class="fas fa-search"></i>
                  </button>
                </div>

                <!-- 搜索建议下拉 -->
                <div
                  class="search-suggestions"
                  v-if="showSearchSuggestions && (searchSuggestions.length > 0 || hotKeywords.length > 0)"
                >
                  <!-- 搜索建议 -->
                  <div v-if="searchSuggestions.length > 0" class="suggestions-section">
                    <div class="suggestions-header">
                      <i class="fas fa-search me-2"></i>搜索建议
                    </div>
                    <div class="suggestions-list">
                      <div
                        class="suggestion-item"
                        v-for="suggestion in searchSuggestions"
                        :key="suggestion"
                        @mousedown="selectSuggestion(suggestion)"
                      >
                        <i class="fas fa-search me-2"></i>
                        {{ suggestion }}
                      </div>
                    </div>
                  </div>

                  <!-- 热门搜索 -->
                  <div v-if="hotKeywords.length > 0" class="hot-keywords-section">
                    <div class="suggestions-header">
                      <i class="fas fa-fire me-2"></i>热门搜索
                    </div>
                    <div class="hot-keywords">
                      <span
                        class="hot-keyword badge bg-light text-dark me-2 mb-2"
                        v-for="(keyword, index) in hotKeywords"
                        :key="keyword"
                        @click="selectHotKeyword(keyword)"
                      >
                        <span class="hot-rank" :class="{ 'top-3': index < 3 }">{{ index + 1 }}</span>
                        {{ keyword }}
                      </span>
                    </div>
                  </div>
                </div>
              </div>
            </form>

            <!-- 热门搜索关键词（搜索框下方） -->
            <div class="popular-searches mt-2 d-none d-xl-block">
              <span class="text-muted small me-2">热搜:</span>
              <a
                href="#"
                class="text-decoration-none small me-3"
                v-for="keyword in hotKeywords.slice(0, 6)"
                :key="keyword"
                @click.prevent="selectHotKeyword(keyword)"
              >
                {{ keyword }}
              </a>
            </div>
          </div>
        </div>

        <!-- 右侧功能区域 -->
        <div class="col-3 col-lg-4">
          <div class="header-actions d-flex align-items-center justify-content-end">
            <!-- 消息通知 -->
            <div class="header-action-item d-none d-xl-block">
              <div class="header-action-link notification-trigger" @click="toggleNotificationPopup">
                <i class="fas fa-bell"></i>
                <span class="action-text">通知</span>
                <span
                  class="action-badge badge-danger notification-badge"
                  v-if="unreadCount > 0"
                >
                  {{ unreadCount > 99 ? '99+' : unreadCount }}
                </span>
              </div>
              
              <!-- 通知弹窗 -->
              <div v-if="showNotificationPopup" class="notification-popup" @click.stop>
                <div class="notification-header">
                  <h4>消息通知</h4>
                  <div class="notification-actions">
                    <button 
                      v-if="unreadCount > 0" 
                      @click="markAllAsRead"
                      class="btn-mark-all-read"
                    >
                      全部已读
                    </button>
                    <button @click="showNotificationPopup = false" class="btn-close">
                      <i class="fas fa-times"></i>
                    </button>
                  </div>
                </div>
                
                <div class="notification-body">
                  <div v-if="loadingNotifications" class="notification-loading">
                    <i class="fas fa-spinner fa-spin"></i>
                    <span>加载中...</span>
                  </div>
                  
                  <div v-else-if="notifications.length === 0" class="notification-empty">
                    <i class="fas fa-bell-slash"></i>
                    <p>暂无通知消息</p>
                  </div>
                  
                  <div v-else class="notification-list">
                    <div 
                      v-for="notification in notifications" 
                      :key="notification.id"
                      class="notification-item"
                      :class="{ 'unread': notification.isRead === 0 }"
                      @click="showNotificationDetail(notification)"
                    >
                      <div class="notification-icon">
                        <i :class="getNotificationIcon(notification.type)"></i>
                      </div>
                      <div class="notification-content">
                        <div class="notification-title">{{ notification.title }}</div>
                        <div class="notification-text">{{ notification.content }}</div>
                        <div class="notification-time">{{ formatNotificationTime(notification.createdTime) }}</div>
                      </div>
                      <div v-if="notification.isRead === 0" class="notification-unread-dot"></div>
                    </div>
                  </div>
                </div>
                
                <div class="notification-footer" v-if="notifications.length > 0">
                  <router-link to="/notifications" class="view-all-link" @click="showNotificationPopup = false">
                    查看全部通知
                  </router-link>
                </div>
              </div>
            </div>

            <!-- 收藏夹 -->
            <div class="header-action-item" v-if="userStore.isLoggedIn">
              <router-link to="/favorites" class="header-action-link">
                <i class="fas fa-heart"></i>
                <span class="action-text">收藏</span>
                <span
                  class="action-badge badge-danger"
                  v-if="favoriteCount > 0"
                >
                  {{ favoriteCount > 99 ? '99+' : favoriteCount }}
                </span>
              </router-link>
            </div>

            <!-- 购物车 -->
            <div class="header-action-item" v-if="userStore.isLoggedIn">
              <router-link to="/cart" class="header-action-link">
                <i class="fas fa-shopping-cart"></i>
                <span class="action-text">购物车</span>
                <span
                  class="action-badge badge-primary"
                  v-if="cartStore.totalItems > 0"
                >
                  {{ cartStore.totalItems > 99 ? '99+' : cartStore.totalItems }}
                </span>
              </router-link>
            </div>
          </div>
        </div>
      </div>

      <!-- 导航菜单栏 -->
      <div class="nav-menu-bar d-none d-lg-block">
        <div class="row align-items-center">
          <div class="col-3">
            <!-- 全部商品分类 -->
            <div class="category-menu dropdown">
              <button
                class="btn btn-primary dropdown-toggle category-btn w-100"
                type="button"
                data-bs-toggle="dropdown"
                :class="{ 'show': showCategoryMenu }"
                @click="toggleCategoryMenu"
              >
                <i class="fas fa-bars me-2"></i>
                全部商品分类
              </button>
              <ul class="dropdown-menu category-dropdown w-100" :class="{ 'show': showCategoryMenu }">
                <li v-for="category in mainCategories" :key="category.id">
                  <a
                    class="dropdown-item d-flex justify-content-between align-items-center"
                    :href="`/products?category=${category.slug}`"
                    @mouseover="showSubCategories(category)"
                  >
                    <div>
                      <i :class="category.icon" class="me-2"></i>
                      {{ category.name }}
                    </div>
                    <i class="fas fa-chevron-right" v-if="category.children"></i>
                  </a>

                  <!-- 子分类 -->
                  <div
                    class="sub-categories"
                    v-if="category.children && hoveredCategory === category.id"
                  >
                    <div class="sub-category-content">
                      <div class="row">
                        <div
                          class="col-md-6 col-lg-4"
                          v-for="subCategory in category.children"
                          :key="subCategory.id"
                        >
                          <h6 class="sub-category-title">{{ subCategory.name }}</h6>
                          <ul class="sub-category-list">
                            <li v-for="item in subCategory.items" :key="item.id">
                              <a :href="`/products?category=${item.slug}`">{{ item.name }}</a>
                            </li>
                          </ul>
                        </div>
                      </div>
                    </div>
                  </div>
                </li>
              </ul>
            </div>
          </div>

          <div class="col-9">
            <!-- 主导航菜单 -->
            <nav class="main-nav">
              <ul class="nav nav-horizontal">
                <li class="nav-item">
                  <router-link to="/" class="nav-link">
                    <i class="fas fa-home me-1"></i>首页
                  </router-link>
                </li>

                <li class="nav-item">
                  <router-link to="/brands" class="nav-link">
                    <i class="fas fa-star me-1"></i>品牌馆
                  </router-link>
                </li>
                <li class="nav-item" v-if="userStore.isAdmin">
                  <router-link to="/admin" class="nav-link text-warning">
                    <i class="fas fa-cog me-1"></i>管理后台
                  </router-link>
                </li>
              </ul>
            </nav>
          </div>
        </div>
      </div>

      <!-- 移动端菜单 -->
      <div class="mobile-menu d-lg-none" v-show="showMobileMenu">
        <div class="mobile-search mb-3">
          <form @submit.prevent="handleSearch">
            <div class="input-group">
              <input
                type="text"
                v-model="searchKeyword"
                placeholder="搜索商品..."
                class="form-control"
              />
              <button class="btn btn-primary" type="submit">
                <i class="fas fa-search"></i>
              </button>
            </div>
          </form>
        </div>

        <nav class="mobile-nav">
          <ul class="list-unstyled">
            <li>
              <router-link to="/" class="text-decoration-none d-block py-3 border-bottom">
                <i class="fas fa-home me-3"></i>首页
              </router-link>
            </li>
            <li>
              <router-link to="/products" class="text-decoration-none d-block py-3 border-bottom">
                <i class="fas fa-th me-3"></i>全部商品
              </router-link>
            </li>
            <li>
              <router-link to="/brands" class="text-decoration-none d-block py-3 border-bottom">
                <i class="fas fa-star me-3"></i>品牌馆
              </router-link>
            </li>
            <li v-if="userStore.isLoggedIn">
              <router-link to="/orders" class="text-decoration-none d-block py-3 border-bottom">
                <i class="fas fa-shopping-bag me-3"></i>我的订单
              </router-link>
            </li>
            <li v-if="userStore.isLoggedIn">
              <router-link to="/favorites" class="text-decoration-none d-block py-3 border-bottom">
                <i class="fas fa-heart me-3"></i>我的收藏
              </router-link>
            </li>
            <li v-if="userStore.isAdmin">
              <router-link to="/admin" class="text-decoration-none d-block py-3 border-bottom">
                <i class="fas fa-cog me-3"></i>管理后台
              </router-link>
            </li>
            <li v-if="!userStore.isLoggedIn">
              <router-link to="/login" class="text-decoration-none d-block py-3 border-bottom">
                <i class="fas fa-sign-in-alt me-3"></i>登录注册
              </router-link>
            </li>
          </ul>
        </nav>
      </div>
    </div>
  </header>
</template>

<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { useCartStore } from '@/stores/cart'
import { Message } from '@/utils/message'
import { 
  getUserNotifications, 
  getUnreadNotificationCount, 
  markNotificationAsRead, 
  markAllNotificationsAsRead 
} from '@/api/notification'
import type { Notification } from '@/types/notification'

const router = useRouter()
const userStore = useUserStore()
const cartStore = useCartStore()

// 状态变量
const showMobileMenu = ref(false)
const showCategoryMenu = ref(false)
const showSearchSuggestions = ref(false)
const hoveredCategory = ref(null)

// 通知相关状态
const showNotificationPopup = ref(false)
const notifications = ref<Notification[]>([])
const loadingNotifications = ref(false)
const unreadCount = ref(0)

// 搜索相关
const searchKeyword = ref('')
const searchCategory = ref('')
const searchSuggestions = ref<string[]>([])

// 收藏数量
const favoriteCount = ref(8)

// 热门搜索关键词
const hotKeywords = ref([
  'iPhone 14 Pro',
  '华为Mate50',
  '小米13',
  'MacBook Pro',
  'iPad Air'
])

// 主要分类数据
const mainCategories = ref([
  {
    id: 1,
    name: '手机数码',
    slug: 'electronics',
    icon: 'fas fa-mobile-alt',
    children: [] as any[]
  },
  {
    id: 2,
    name: '服装鞋靴',
    slug: 'clothing',
    icon: 'fas fa-tshirt',
    children: [] as any[]
  },
  {
    id: 3,
    name: '家用电器',
    slug: 'appliances',
    icon: 'fas fa-tv',
    children: [] as any[]
  },
  {
    id: 4,
    name: '家居家装',
    slug: 'home',
    icon: 'fas fa-couch',
    children: [] as any[]
  },
  {
    id: 5,
    name: '运动户外',
    slug: 'sports',
    icon: 'fas fa-running',
    children: [] as any[]
  },
  {
    id: 6,
    name: '汽车用品',
    slug: 'automotive',
    icon: 'fas fa-car',
    children: [] as any[]
  },
  {
    id: 7,
    name: '母婴用品',
    slug: 'baby',
    icon: 'fas fa-baby',
    children: [] as any[]
  },
  {
    id: 8,
    name: '食品生鲜',
    slug: 'food',
    icon: 'fas fa-apple-alt',
    children: [] as any[]
  },
  {
    id: 9,
    name: '图书文娱',
    slug: 'books',
    icon: 'fas fa-book',
    children: [] as any[]
  },
  {
    id: 10,
    name: '医药保健',
    slug: 'health',
    icon: 'fas fa-medkit',
    children: [] as any[]
  }
])

// 方法
const toggleMobileMenu = () => {
  showMobileMenu.value = !showMobileMenu.value
}

const toggleCategoryMenu = () => {
  showCategoryMenu.value = !showCategoryMenu.value
}

const showSubCategories = (category: any) => {
  hoveredCategory.value = category.id
}

const onSearchInput = () => {
  if (searchKeyword.value.length > 1) {
    // 模拟搜索建议
    searchSuggestions.value = [
      `${searchKeyword.value} pro`,
      `${searchKeyword.value} max`,
      `${searchKeyword.value} 手机`,
      `${searchKeyword.value} 配件`
    ].slice(0, 5)
  } else {
    searchSuggestions.value = []
  }
}

const hideSearchSuggestions = () => {
  setTimeout(() => {
    showSearchSuggestions.value = false
  }, 200)
}

const selectSuggestion = (suggestion: string) => {
  searchKeyword.value = suggestion
  showSearchSuggestions.value = false
  handleSearch()
}

const selectHotKeyword = (keyword: string) => {
  searchKeyword.value = keyword
  showSearchSuggestions.value = false
  handleSearch()
}

const handleSearch = () => {
  if (searchKeyword.value.trim()) {
    router.push({
      path: '/products',
      query: {
        keyword: searchKeyword.value,
        category: searchCategory.value
      }
    })
    showMobileMenu.value = false
    showSearchSuggestions.value = false
  }
}

const handleLogout = async () => {
  try {
    await userStore.logout()
    Message.success('退出成功')
    router.push('/')
  } catch (error) {
    console.error('退出失败:', error)
    Message.error('退出失败')
  }
}

// 通知相关方法
const toggleNotificationPopup = () => {
  showNotificationPopup.value = !showNotificationPopup.value
  if (showNotificationPopup.value && userStore.isLoggedIn) {
    loadNotifications()
  }
}

const loadNotifications = async () => {
  
  loadingNotifications.value = true
  try {
    const [notificationRes, unreadRes] = await Promise.all([
    ])
    
    notifications.value = notificationRes.data.records || []
    unreadCount.value = unreadRes.data || 0
  } catch (error) {
    console.error('获取通知失败:', error)
    notifications.value = []
    unreadCount.value = 0
  } finally {
    loadingNotifications.value = false
  }
}

const showNotificationDetail = async (notification: Notification) => {
  // 如果是未读通知，标记为已读
  if (notification.isRead === 0) {
    try {
      await markNotificationAsRead(notification.id!)
      notification.isRead = 1
      unreadCount.value = Math.max(0, unreadCount.value - 1)
    } catch (error) {
      console.error('标记通知已读失败:', error)
    }
  }
  
  // 显示通知详情（可以扩展为弹窗或跳转）
  if (notification.actionUrl) {
    window.open(notification.actionUrl, '_blank')
  } else {
    Message.info(`通知内容: ${notification.content}`)
  }
  
  showNotificationPopup.value = false
}

const markAllAsRead = async () => {
  try {
    notifications.value.forEach(n => n.isRead = 1)
    unreadCount.value = 0
    Message.success('已标记所有通知为已读')
  } catch (error) {
    console.error('标记全部已读失败:', error)
    Message.error('标记失败')
  }
}

const getNotificationIcon = (type: number) => {
  switch (type) {
    case 1: return 'fas fa-info-circle text-info'
    case 2: return 'fas fa-shopping-cart text-success'
    case 3: return 'fas fa-box text-warning'
    case 4: return 'fas fa-exclamation-triangle text-danger'
    default: return 'fas fa-bell text-primary'
  }
}

const formatNotificationTime = (dateStr: string) => {
  const date = new Date(dateStr)
  const now = new Date()
  const diff = now.getTime() - date.getTime()
  
  const minutes = Math.floor(diff / (1000 * 60))
  const hours = Math.floor(diff / (1000 * 60 * 60))
  const days = Math.floor(diff / (1000 * 60 * 60 * 24))
  
  if (minutes < 1) return '刚刚'
  if (minutes < 60) return `${minutes}分钟前`
  if (hours < 24) return `${hours}小时前`
  if (days < 7) return `${days}天前`
  
  return date.toLocaleDateString('zh-CN', {
    month: 'short',
    day: 'numeric',
    hour: '2-digit',
    minute: '2-digit'
  })
}

// 页面点击事件处理
const handleDocumentClick = (event: Event) => {
  const target = event.target as HTMLElement
  if (!target.closest('.category-menu')) {
    showCategoryMenu.value = false
  }
  if (!target.closest('.notification-trigger') && !target.closest('.notification-popup')) {
    showNotificationPopup.value = false
  }
}

onMounted(() => {
  document.addEventListener('click', handleDocumentClick)
  // 如果用户已登录，加载通知数据
  if (userStore.isLoggedIn) {
    loadNotifications()
  }
})

// 监听用户登录状态变化
watch(() => userStore.isLoggedIn, (newVal) => {
  if (newVal) {
    loadNotifications()
  } else {
    notifications.value = []
    unreadCount.value = 0
    showNotificationPopup.value = false
  }
})

// 组件销毁时清理事件监听
onBeforeUnmount(() => {
  document.removeEventListener('click', handleDocumentClick)
})
</script>

<style scoped>
/* 顶部栏优化 */
.topheader {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-bottom: 1px solid #dee2e6;
  padding: 8px 0;
  font-size: 13px;
}

.default-msg {
  color: #28a745 !important;
  font-weight: 500;
}

.customer-links a {
  color: #666;
  text-decoration: none;
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 4px;
  transition: all 0.3s ease;
}

.customer-links a:hover {
  color: #007bff;
  background: rgba(0, 123, 255, 0.1);
}

/* Logo区域优化 */
.logo h2 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -1px;
}

/* 搜索框优化 */
.header-search {
  max-width: 100%;
}

.search-wrapper {
  position: relative;
}

.searchField {
  display: flex;
  border: 2px solid #007bff;
  border-radius: 25px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 123, 255, 0.1);
}


.header-search input[type="text"] {
  flex: 1;
  border: none;
  padding: 12px 15px;
  font-size: 14px;
}

.header-search input[type="text"]:focus {
  outline: none;
  box-shadow: none;
}

.header-search input[type="text"]::placeholder {
  color: #999;
}

.header-search .action {
  background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
  border: none;
  padding: 12px 20px;
  color: white;
  cursor: pointer;
  font-weight: 500;
  min-width: 80px;
}

.header-search .action:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3);
}

/* 搜索建议 */
.search-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  margin-top: 2px;
  max-height: 400px;
  overflow-y: auto;
}

.suggestions-header {
  padding: 10px 15px;
  background: #f8f9fa;
  font-size: 12px;
  font-weight: 600;
  color: #666;
  border-bottom: 1px solid #e9ecef;
}

.suggestion-item {
  padding: 10px 15px;
  cursor: pointer;
  border-bottom: 1px solid #f8f9fa;
  color: #333;
  font-size: 14px;
}

.suggestion-item:hover {
  background: #f8f9fa;
  color: #007bff;
}

.hot-keywords {
  padding: 15px;
}

.hot-keyword {
  cursor: pointer;
  border: 1px solid #dee2e6 !important;
  color: #666 !important;
  background: white !important;
  transition: all 0.3s ease;
}

.hot-keyword:hover {
  background: #007bff !important;
  color: white !important;
  border-color: #007bff !important;
}

.hot-rank {
  display: inline-block;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 50%;
  background: #f8f9fa;
  color: #666;
  font-size: 10px;
  margin-right: 5px;
}

.hot-rank.top-3 {
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
  color: white;
  font-weight: bold;
}

/* 热门搜索 */
.popular-searches {
  font-size: 12px;
}

.popular-searches a {
  color: #666;
  padding: 2px 6px;
  border-radius: 12px;
  transition: all 0.3s ease;
}

.popular-searches a:hover {
  background: #f8f9fa;
  color: #007bff;
}

/* 右侧功能区域优化 */
.header-actions {
  gap: 5px;
}

.header-action-item {
  position: relative;
}

.header-action-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: #666;
  padding: 6px 8px;
  border-radius: 6px;
  transition: all 0.3s ease;
  position: relative;
  min-width: 45px;
}

.header-action-link:hover {
  color: #007bff;
  background: rgba(0, 123, 255, 0.1);
  transform: translateY(-1px);
}

.header-action-link i {
  font-size: 18px;
  margin-bottom: 4px;
  transition: all 0.3s ease;
}

.action-text {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.action-badge {
  position: absolute;
  top: 3px;
  right: 8px;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  font-size: 9px;
  font-weight: 600;
  text-align: center;
  border-radius: 8px;
  padding: 0 4px;
  color: white;
}

.badge-danger {
  background: #dc3545;
}

.badge-primary {
  background: #007bff;
}

/* 导航菜单栏 */
.nav-menu-bar {
  border-top: 1px solid #e9ecef;
  padding: 10px 0;
  background: #fafafa;
}

.category-btn {
  background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
  border: none;
  font-weight: 500;
  border-radius: 8px;
  padding: 10px 15px;
  transition: all 0.3s ease;
}

.category-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3);
}

.category-dropdown {
  max-height: 500px;
  overflow-y: auto;
  border: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  margin-top: 5px;
}

.category-dropdown .dropdown-item {
  padding: 12px 20px;
  border-bottom: 1px solid #f8f9fa;
  transition: all 0.3s ease;
}

.category-dropdown .dropdown-item:hover {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  color: #007bff;
  transform: translateX(5px);
}

.sub-categories {
  position: absolute;
  left: 100%;
  top: 0;
  width: 600px;
  background: white;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  padding: 20px;
  z-index: 1001;
}

.sub-category-title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 10px;
  padding-bottom: 5px;
  border-bottom: 1px solid #f0f0f0;
}

.sub-category-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sub-category-list li {
  margin-bottom: 5px;
}

.sub-category-list a {
  color: #666;
  text-decoration: none;
  font-size: 13px;
  padding: 2px 0;
  display: block;
  transition: color 0.3s ease;
}

.sub-category-list a:hover {
  color: #007bff;
}

/* 主导航 */
.main-nav {
  margin-left: 20px;
}

.nav-horizontal {
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-horizontal .nav-item {
  margin-right: 30px;
}

.nav-horizontal .nav-link {
  color: #333;
  text-decoration: none;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 6px;
  transition: all 0.3s ease;
  font-size: 14px;
}

.nav-horizontal .nav-link:hover,
.nav-horizontal .nav-link.router-link-active {
  color: #007bff;
  background: rgba(0, 123, 255, 0.1);
}

.nav-horizontal .dropdown-menu {
  border: none;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  margin-top: 5px;
}

.nav-horizontal .dropdown-item {
  padding: 8px 16px;
  font-size: 14px;
  transition: all 0.3s ease;
}

.nav-horizontal .dropdown-item:hover {
  background: #f8f9fa;
  color: #007bff;
}

/* 移动端菜单优化 */
.mobile-menu {
  background: white;
  border-top: 2px solid #007bff;
  padding: 20px 0;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}

.mobile-search .form-select {
  max-width: 100px;
}

.mobile-nav a {
  color: #333;
  font-weight: 500;
  transition: all 0.3s ease;
  font-size: 15px;
}

.mobile-nav a:hover {
  color: #007bff;
  background: rgba(0, 123, 255, 0.05);
  transform: translateX(10px);
}

/* 徽章优化 */
.badge {
  font-size: 10px;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  border-radius: 9px;
  font-weight: 600;
}

/* 响应式优化 */
@media (max-width: 1200px) {
  .nav-horizontal .nav-item {
    margin-right: 20px;
  }

  .popular-searches {
    display: none !important;
  }
}

@media (max-width: 992px) {
  .nav-menu-bar {
    display: none !important;
  }
}

@media (max-width: 768px) {
  .logo h2 {
    font-size: 1.5rem;
  }

  .logo small {
    display: none !important;
  }

  .searchField {
    border-radius: 8px;
  }

  .header-search .action {
    min-width: 50px;
    padding: 12px 15px;
  }

  .mobile-nav a {
    font-size: 16px;
    padding: 15px 0 !important;
  }

  /* 头部功能区域移动端优化 */
  .header-actions {
    gap: 5px;
  }

  .header-action-link {
    padding: 6px 8px;
    min-width: 40px;
  }

  .header-action-link i {
    font-size: 16px;
    margin-bottom: 2px;
  }

  .action-text {
    font-size: 10px;
  }

  .action-badge {
    top: 1px;
    right: 4px;
    font-size: 8px;
    min-width: 14px;
    height: 14px;
    line-height: 14px;
  }
}

@media (max-width: 576px) {
  .topheader .col-md-4:first-child .d-flex > div {
    margin-right: 10px !important;
  }

  .topheader .phone-no span {
    display: none;
  }

  .customer-links {
    font-size: 12px;
  }

  .customer-links li {
    margin-left: 8px !important;
  }
}

/* 动画效果 */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.search-suggestions,
.dropdown-menu {
  animation: slideDown 0.3s ease-out;
}

/* 滚动条优化 */
.category-dropdown::-webkit-scrollbar {
  width: 6px;
}

.category-dropdown::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.category-dropdown::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.category-dropdown::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* 通知弹窗样式 */
.notification-trigger {
  position: relative;
  cursor: pointer;
}

.notification-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 18px;
  height: 18px;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  background: #ff4757;
  color: white;
  font-weight: bold;
}

.notification-popup {
  position: absolute;
  top: 100%;
  right: 0;
  width: 380px;
  max-height: 500px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  border: 1px solid #e9ecef;
  z-index: 1050;
  animation: slideDown 0.3s ease-out;
}

.notification-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
  background: #f8f9fa;
  border-radius: 8px 8px 0 0;
}

.notification-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.notification-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-mark-all-read {
  background: none;
  border: none;
  color: #007bff;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.btn-mark-all-read:hover {
  background: #f0f8ff;
}

.btn-close {
  background: none;
  border: none;
  color: #999;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.btn-close:hover {
  color: #666;
}

.notification-body {
  max-height: 350px;
  overflow-y: auto;
}

.notification-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: #666;
  gap: 10px;
}

.notification-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: #999;
}

.notification-empty i {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.notification-empty p {
  margin: 0;
  font-size: 14px;
}

.notification-list {
  padding: 0;
}

.notification-item {
  display: flex;
  align-items: flex-start;
  padding: 16px 20px;
  border-bottom: 1px solid #f5f5f5;
  cursor: pointer;
  position: relative;
}

.notification-item:hover {
  background: #f8f9fa;
}

.notification-item:last-child {
  border-bottom: none;
}

.notification-item.unread {
  background: linear-gradient(90deg, #f0f8ff 0%, #ffffff 100%);
}

.notification-item.unread::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #007bff;
}

.notification-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  border-radius: 50%;
  margin-right: 12px;
}

.notification-icon i {
  font-size: 16px;
}

.notification-content {
  flex: 1;
  min-width: 0;
}

.notification-title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 4px;
  line-height: 1.4;
}

.notification-text {
  font-size: 13px;
  color: #666;
  line-height: 1.4;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.notification-time {
  font-size: 11px;
  color: #999;
}

.notification-unread-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  background: #007bff;
  border-radius: 50%;
  margin-left: 8px;
  margin-top: 6px;
}

.notification-footer {
  padding: 12px 20px;
  border-top: 1px solid #eee;
  text-align: center;
  background: #fafafa;
  border-radius: 0 0 8px 8px;
}

.view-all-link {
  color: #007bff;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}

.view-all-link:hover {
  color: #0056b3;
  text-decoration: none;
}

/* 通知弹窗滚动条 */
.notification-body::-webkit-scrollbar {
  width: 4px;
}

.notification-body::-webkit-scrollbar-track {
  background: #f5f5f5;
}

.notification-body::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 2px;
}

.notification-body::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* 响应式处理 */
@media (max-width: 1400px) {
  .notification-popup {
    width: 320px;
  }
}

@media (max-width: 768px) {
  .notification-popup {
    width: 280px;
    right: -60px;
  }
}
</style> 